/*public js xianhuachneg.com*/

/*Tab Search style*/
function selectsearch(theA, word) {
    obj = document.getElementById("selectsearch").getElementsByTagName("a");
    for (var i = 0; i < obj.length; i++) {
        obj[i].className = '';
    }
    theA.className = 'choose';
    if (word == 'restaurant_name') {
        document.getElementById('main_a_serach').action = "search_s.html";//Test url
    } else if (word == 'food_name') {
        document.getElementById('main_a_serach').action = "search_p.html";//Test url
    }
}
//获取图片
function getImage() {
    document.getElementById('num').src = '/getImage?' + (new Date()).getTime();
}
//忘记密码
function ablur() {
    var username = $("#username").val();
    if (username == null || username == "") {
        $("#email").val("");
    } else {
        $.get("/verification?username=" + username, function (data) {
            if (data != "Fail") {
                var jsonObj = JSON.parse(data);//转换为json对象
                var email = jsonObj.email;
                $("#email").val(email);
            } else {
                $("#email").val("");
            }
        })
    }
}
//发货
function admin_shop_state(order_id) {
    var v = confirm("确定发货？");
    if(v){
        $.get("/admin/adminshopstate?order_id=" + order_id, function (data) {
            if (data == "OK") {
                window.location.href="/admin/adminOrderList";
            }
        })
    }
}
//签收
function admin_shop_state1(order_id) {
    var v = confirm("确定签收？");
    if(v){
        $.get("/admin/adminshopstate1?order_id=" + order_id, function (data) {
            if (data == "OK") {
                window.location.href="/order/history";
            }
        })
    }
}

//付款
function pay(order_id) {
    var v = confirm("确定支付？");
    if(v){
        $.get("/order/pay?order_id=" + order_id, function (data) {
            if (data == "OK") {
                alert("支付成功");
                window.location.href="/order/history";
            }
        })
    }
}
//更改密码信息
function verify2() {
    var email = $("#email").val();
    var password = $("#password").val();
    var code = $("#code").val();
    if (code == null || code == "" || password == null || password == "" || email == null || email == "") {
        alert("信息不能为空");
    } else {
        $.post("/user/verify", $('#verifyFrom').serialize(), function (data) {
            if (data == "OK") {
                alert("修改成功");
                window.location.href = "/login";
            } else {
                alert("验证码错误，请输入正确的验证码");
            }
        })
    }
    return false;
}
//获取邮箱验证码
function verify1() {
    var email = $("#email").val();
    if (email != null && email != "") {
        $.post("/verifeCode", $('#verifyFrom').serialize(), function (data) {
            if (data == "OK") {
                alert("已发送验证码，请注意查收");
            } else {
                alert("服务器内部错误");
            }
        })
    } else {
        alert("账号不存在,请输入正确的账号");
    }
    return false;
}
//添加购物车
function mealCart(meal_id){
    $.get("/add_meal?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            alert("添加成功，查看请到购物车");
        } else {
            alert("请先登录");
        }
    })
}
//收藏
function mealCollect(meal_id){
    $.get("/mealCollect?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            alert("收藏成功");
            location.reload();
        } else {
            alert("请先登录");
        }
    })
}
//取消收藏
function mealCollectOver(meal_id){
    $.get("/mealCollectOver?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            alert("取消收藏成功");
            location.reload();
        } else {
            alert("请先登录");
        }
    })
}

//减少
function minmeal(meal_id){
    $.get("/minmeal?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            location.reload();
        }
    })
}
//增加数量
function addmeal(meal_id){
    $.get("/addmeal?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            location.reload();
        }
    })
}
//清除食物
function deletemealcart(meal_id){
    $.get("/deletemealcart?meal_id=" + meal_id, function (data) {
        if (data == "OK") {
            location.reload();
        }
    })
}
//取消订单
function overOrder(order_id){
    var v = confirm("确定取消订单？");
    if(v){
        $.get("/overOrder?order_id=" + order_id, function (data) {
            if (data == "OK") {
                window.location.href="/order/history";
            }
        })
    }
}
//删除菜品
function remove_meal(meal_id){
    var v = confirm("确定删除此菜单？");
    if(v){
        $.get("/admin/remove_meal?meal_id=" + meal_id, function (data) {
            if (data == "OK") {
                window.location.href="/admin/mealList";
            }
        })
    }
}

//INDEX TAB LIST
window.onload = function () {
    var oLi = document.getElementById("Indextab").getElementsByTagName("li");
    var oUl = document.getElementById("Indexcontent").getElementsByTagName("ul");
    for (var i = 0; i < oLi.length; i++) {
        oLi[i].index = i;
        oLi[i].onclick = function () {
            for (var n = 0; n < oLi.length; n++) oLi[n].className = "";
            this.className = "current";
            for (var n = 0; n < oUl.length; n++) oUl[n].style.display = "none";
            oUl[this.index].style.display = "block"
        }
    }
}

/*change radio background color*/
function changeColor(arg) {
    var rdCount = document.getElementsByName("rdColor").length;
    for (i = 1; i <= rdCount; i++) {
        document.getElementById("style" + i).style.fontWeight = "normal";
        document.getElementById("style" + i).style.backgroundColor = "";
        document.getElementById("style" + i).style.boxShadow = "none";
        document.getElementById("style" + i).style.border = "none";
    }
    document.getElementById("style" + arg).style.backgroundColor = "#fff5cc";
    document.getElementById("style" + arg).style.fontWeight = "bold";
    document.getElementById("style" + arg).style.boxShadow = "3px 2px 10px #dedede";
    document.getElementById("style" + arg).style.border = "1px #ffe580 solid";
}
